package com.example.common.utils.security;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * 用户密码工具类
 * @author ZhengDing
 * @date 2022/2/20 18:03
 */

public class PasswordUtils {
    
    /**
     * 对原始密码进行加密
     * 针对前端传过来的用户密码为原始值的情况
     * 建议前端加密后传输，后端进行 md5 转换后存储到数据库
     */
    public static String encryptPassword(String rawPassword) {
        String encryptedPassword = DigestUtils.md5DigestAsHex(rawPassword.getBytes(StandardCharsets.UTF_8));
        return encryptedPassword;
    }
    
    public static void main(String[] args) {
        System.out.println(encryptPassword("123"));
        System.out.println(encryptPassword("123456"));
        System.out.println(encryptPassword("asdasdsf"));
        System.out.println(encryptPassword("asd^&*&*(&(*"));
        System.out.println(encryptPassword("sdfsdfa9809890312(*)"));
    }
}
